package com.gjintel.business.proj.controller;

import com.gjintel.auction.business.model.AuctionInfo;
import com.gjintel.auction.business.service.IAuctionService;
import com.gjintel.business.proj.model.ProjectPause;
import com.gjintel.business.proj.service.INotifyService;
import com.gjintel.business.proj.service.IProjectInfoService;
import com.gjintel.business.proj.service.IProjectPauseService;
import com.gjintel.framework.common.service.IDepositService;
import com.gjintel.framework.constant.Constant;
import com.gjintel.framework.dataset.model.DataSet;
import com.gjintel.framework.dataset.service.IDataSetService;
import com.gjintel.framework.holidayset.service.IHolidaySetService;
import com.gjintel.framework.projecttype.model.ProjectType;
import com.gjintel.framework.projecttype.service.IProjectTypeService;
import com.gjintel.framework.res.model.Resources;
import com.gjintel.framework.user.model.User;
import com.gjintel.framework.util.FileResUtil;
import com.gjintel.sdk.util.DateUtils;
import com.gjintel.sdk.util.StringUtil;
import com.gjintel.workflow.trade.service.IWorkflowProcessInstanceService;
import net.sf.json.JSONArray;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/business/projectPause")
public class ProjectPauseController {
	@Autowired
	private IProjectPauseService profectPauseService;
	@Autowired
	private IProjectInfoService projectInfoService;
	@Autowired
	private RuntimeService runtimeService;
	@Autowired
	private IWorkflowProcessInstanceService workflowService;
	@Autowired
	private IProjectTypeService projectTypeService;
	@Autowired
	private INotifyService notifyService;
	@Autowired
	private IDepositService depositService;
	@Autowired
	private IWorkflowProcessInstanceService workflowProcessInstanceService;
	@Autowired
	private IAuctionService auctionService;

	public static final String PAUSE_RESTORE_J = "1";//竞价公示暂停重启
    public static final String PAUSE_REVOKE_J = "2";//竞价公示暂停撤销
	public static final String PAUSE_RESTORE_Z = "3";//竞价公示暂停重启
    public static final String PAUSE_FLOW_Z = "4";//竞价公示暂停流标

	public static final String PAUSE_CATEGORY_J ="0";
    public static final String PAUSE_CATEGORYZ_Z ="1";

    @Autowired
    private IDataSetService dataSetService;

    @Autowired
    private IHolidaySetService holidaySetService;


	/**
	 * @description 进入编辑暂停流程页面
	 * @author shy
	 * @date 2016-8-31
	 */
	@RequestMapping("/leader/prjectPauserPage")
	@ResponseBody
	public ModelAndView toPrjectPauserPage(HttpSession session, String projectId, String category) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/proj/leader/projectPause-input");
		mv.addObject("projectId", projectId);
		mv.addObject("category",category);
		return mv;
	}

	/**
	 * @description 文件上传
	 * @author shy
	 * @date 2016-9-1
	 */
	@RequestMapping("/upload")
	public void upload(HttpServletRequest request, HttpServletResponse response, Integer functionFlog)
			throws IOException {
		PrintWriter out = response.getWriter();
		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		// 取得request中的文件,获取一个list集合
		MultipartFile file = multipartRequest.getFile("Filedata");
		// 得到文件的相对路径
		String relativePath = File.separator + "project";
		String uploadPath = request.getSession().getServletContext().getRealPath("file_resource") + relativePath;
		File filePath = new File(uploadPath);
		// 判断文件夹是否存在，如果不存在给与创建出来
		if (!filePath.exists()) {
			filePath.mkdirs();
		}
		String fileName = file.getOriginalFilename();
		Resources res = new Resources();
		String exeName = fileName.substring(fileName.lastIndexOf("."), fileName.length());
		res.setExeName(exeName);
		res.setFilePath(relativePath);
		res.setFileSize(file.getSize());
		res.setOldName(fileName);
		res.setFunctionFlog(functionFlog);// 设置文件功能类型(暂停文件 8)
		FileResUtil.addFileRes(res); // 保存文件记录
		File newFile = new File(uploadPath, res.getId() + res.getExeName());
		file.transferTo(newFile);
		out.write(res.getId());
		out.flush();
		out.close();
	}

	/**
	 * @description 保存暂停申请
	 * @author shy
	 * @throws IOException
	 * @date 2016-9-1
	 */
	@RequestMapping("/leader/saveProjectPause")
	public void saveProjectPause(HttpSession session, ProjectPause projectPause, HttpServletResponse resp,String resultString) throws IOException {
            if(StringUtil.isEmpty(projectPause.getReason())){
            	resp.getWriter().print(Constant.REASON_NULL);
            }else{
		    User u = (User) session.getAttribute("loginUser");
			this.profectPauseService.saveProjectPause(u, projectPause, resultString);
			resp.getWriter().print(Constant.SAVE_SUCCESS);
			}
	}

	/**
	 * @description 业务管理员审核页面
	 * @author shy
	 * @date 2016-9-1
	 */

	@RequestMapping("/bizmanager/projectListPage")
	public ModelAndView projectList() {
		ModelAndView mv = new ModelAndView("/proj/bizmanager/project");
		return mv;
	}

//	/**
//	 * @description 业务管理员获取项目列表
//	 * @author shy
//	 * @date 2016-9-1
//	 */
//	@RequestMapping("/bizmanager/projectList")
//	public void getProjectList(HttpSession session, HttpServletResponse resp, Page page,ProjectInfo project) {
//		this.profectPauseService.getProjectList(page,project);
//		List<ProjectInfo> list = page.getResult();
//		for (ProjectInfo pro : list) {
//			Dictionary dicProStatus = DictUtil.dict("proj_status", pro.getStatus()+"");
//			if(dicProStatus!=null){
//				pro.setStatusName(dicProStatus.getName());//项目状态
//			}else{
//				pro.setStatusName("未知");//项目状态
//			}
//		}
//		JSONObject jsonObject = CommUtil.getPageJSONData(page, true);
//		try {
//			resp.getWriter().print(jsonObject);
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//
//	}

	/**
	 * @description 进入暂停审核
	 * @author shy
	 * @date 2016-9-2
	 */
	@RequestMapping("/bizmanager/toPauseAuditPage")
	@ResponseBody
	public ModelAndView toPauserAuditPage(HttpSession session, String projectId,String category ) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/auction/bizmanager/projectPause-audit");
		mv.addObject("projectId", projectId);
		mv.addObject("category", category);
		return mv;
	}

	/**
	 * @description 业务管理员审核
	 * @author shy
	 * @throws IOException
	 * @date 2016-9-2
	 */
	@RequestMapping("/bizmanager/AuditProjectPause")
	@ResponseBody
	public void AuditProjectPause(ProjectPause projectPause, HttpSession session, HttpServletResponse resp, String pauseCategory) throws IOException {
		User user = (User) session.getAttribute("loginUser");
		this.profectPauseService.pauseAuditNew(user, projectPause, pauseCategory);
		resp.getWriter().print(Constant.SAVE_SUCCESS);
	}

//	/**
//	 * @description 进入项目撤销页面
//	 * @author shy
//	 * @date 2016-9-2
//	 */
//	@RequestMapping("/bizmanager/projectRevokePage")
//	@ResponseBody
//	public ModelAndView projectRevokePage(HttpSession session, String projectId) {
//		ModelAndView mv = new ModelAndView();
//		mv.setViewName("/auction/bizmanager/project-revoke");
//		mv.addObject("projectId", projectId);
//
//		return mv;
//	}

//	/**
//	 * @description 进入流标页面
//	 * @author shy
//	 * @date 2016-9-2
//	 */
//	@RequestMapping("/bizmanager/projectFlowPage")
//	@ResponseBody
//	public ModelAndView projectFlowPage(HttpSession session, String projectId) {
//		ModelAndView mv = new ModelAndView();
//		mv.setViewName("auction/center_auditor/project-flow");
//		mv.addObject("projectId", projectId);
//		return mv;
//	}

//	/**
//	 * @description 项目撤销
//	 * @author shy
//	 * @throws IOException
//	 * @date 2016-9-2
//	 */
//	@RequestMapping("/bizmanager/projectRevoke")
//	@ResponseBody
//	public void projectRevoke(HttpSession session, String projectId, ProjectPause projectPause, String pauseCategory,
//			HttpServletResponse resp) throws IOException {
//		User user = (User) session.getAttribute("loginUser");
//		if(StringUtil.isEmpty(projectPause.getRevokeReason())){
//			resp.getWriter().print(Constant.REASON_NULL);
//		}else{
//		this.profectPauseService.projectRevoke(user, projectPause, pauseCategory);
//		resp.getWriter().print(Constant.SAVE_SUCCESS);
//		}
//	}

	/**
	 * @description 项目流标
	 * @author shy
	 * @throws IOException
	 * @date 2016-9-2
	 */
	@RequestMapping("/bizmanager/projectFlow")
	@ResponseBody
	public void projectFlow(HttpSession session, String projectId, ProjectPause projectPause, String pauseCategory,
			HttpServletResponse resp) throws IOException {
		User user = (User) session.getAttribute("loginUser");
		this.profectPauseService.projectFlow(user, projectPause, pauseCategory);
		resp.getWriter().print(Constant.SAVE_SUCCESS);
	}

//	/**
//	 * @description 项目重启页面(竞价公示)
//	 * @author shy
//	 * @date 2016-9-2
//	 */
//	@RequestMapping("/leader/toRestartPageJ")
//	@ResponseBody
//	public ModelAndView toRestartPageJ(HttpSession session, String projectId) {
//		ModelAndView mv = new ModelAndView();
//		ProjectInfo pro = projectInfoService.get(ProjectInfo.class, projectId);
//		mv.setViewName("/proj/leader/project-restoreJ");
//		mv.addObject("projectId", projectId);
//		mv.addObject("bidStartTime", pro.getBidStartTime());
//		mv.addObject("auditable",false);
//		//if(pro.getAuditable()==true){
//			mv.addObject("validTime", pro.getValidTime());
//			//mv.addObject("auditable",true);
//		//}
//		return mv;
//	}

//	/**
//	 * @description 项目重启页面
//	 * @author shy
//	 * @date 2016-9-2
//	 */
//	@RequestMapping("/leader/toRestartPageZ")
//	@ResponseBody
//	public ModelAndView toRestartPageZ(HttpSession session, String projectId) {
//		ModelAndView mv = new ModelAndView();
//		ProjectInfo pro = projectInfoService.get(ProjectInfo.class, projectId);
//		mv.setViewName("/proj/leader/project-restoreZ");
//		mv.addObject("projectId", projectId);
//		mv.addObject("showEndTime", pro.getShowEndTime());
//		return mv;
//	}

//	/**
//	 * @description 项目重启(竞价公示暂停)
//	 * @author shy
//	 * @throws Exception
//	 * @date 2016-9-3
//	 */
//	@RequestMapping("/leader/projectRestoreJ")
//	@ResponseBody
//	public void projectRestoreJ(HttpSession session, ProjectPause projectPause, String pauseCategory,
//			String bidStartDateStr, String bidStartTimeStr, HttpServletResponse resp) throws Exception {
//		User user = (User) session.getAttribute("loginUser");
//		ProjectInfo pro = projectInfoService.get(ProjectInfo.class, projectPause.getProjectId());
//		Date newDate=null;
//		String bidStartStr=bidStartDateStr+" "+bidStartTimeStr+":00:00";
//		newDate=StringUtil.StringToDate(bidStartStr);
//
//		if (newDate.compareTo(new Date()) < 0 || newDate.compareTo(pro.getBidStartTime()) <= 0) {
//			resp.getWriter().print("time_orror");
//		} else {
//			// 通知银行
//			int result = depositService.editOpenTime(pro.getId());
//			if (result != 1) {
//				resp.getWriter().print(Constant.SAVE_UN_SUCCESS);
//				return;
//			}
//			//projectInfo表数据更新
//			this.profectPauseService.projectRestore(user, projectPause, pauseCategory, newDate, pro);
//			//非评标项目
//				    Task task = workflowProcessInstanceService.findTask(pro.getWorkflowId());
//					Map<String, Object> variables = new HashMap<String, Object>();
//					//variables.put("teminate", 7);
//					variables.put("teminate", ProjectStatus.WAIT_SHOT.toString());
//					variables.put("showTime", StringUtil.getISODate(pro.getBidStartTime()));
//					workflowProcessInstanceService.complete(task.getId(), variables);
//			        resp.getWriter().print(Constant.SAVE_SUCCESS);
//		}
//	}

//	/**
//	 * @description 项目重启(中标公示暂停)
//	 * @author shy
//	 * @throws Exception
//	 * @date 2016-9-3
//	 */
//	@RequestMapping("/leader/projectRestoreZ")
//	@ResponseBody
//	public void projectRestoreZ(HttpSession session, ProjectPause projectPause, String pauseCategory,
//			String showEndTime, HttpServletResponse resp) throws Exception {
//		User user = (User) session.getAttribute("loginUser");
//		ProjectInfo pro = projectInfoService.get(ProjectInfo.class, projectPause.getProjectId());
//		Date newDate=null;
//		String newShowEndTime =showEndTime+" "+"23:59:59";
//		newDate=StringUtil.StringToDate(newShowEndTime);
//		if(newDate.compareTo(new Date())<0 || newDate.compareTo(pro.getShowEndTime())<=0){
//			resp.getWriter().print("time_orror");
//		}else{
//	       this.profectPauseService.projectRestore(user, projectPause, pauseCategory, newDate,pro);
//	        	//非评标项目
//				    Task task = workflowProcessInstanceService.findTask(pro.getWorkflowId());
//					Map<String, Object> variables = new HashMap<String, Object>();
//					//variables.put("bidTeminate", 10);
//					variables.put("bidTeminate", ProjectStatus.SHOWING.toString());
//					variables.put("resultShowTime", StringUtil.getISODate(pro.getShowEndTime()));
//					workflowProcessInstanceService.complete(task.getId(), variables);
//		            resp.getWriter().print(Constant.SAVE_SUCCESS);
//		}
//	}


	/**
	 * @description 获取项目类型
	 * @author shy
	 * @throws IOException
	 * @date 2016-9-21
	 */
	@RequestMapping("/bizmanager/getProjectType")
	@ResponseBody
	public JSONArray getProjectType(HttpServletResponse resp) throws IOException{
		List<ProjectType> projectTypeList = projectTypeService.findAll();
		return JSONArray.fromObject(projectTypeList);
	}



	/**
	 * @description 提交重启申请页面
	 * @author shy
	 * @date 2016-9-2
	 */
	@RequestMapping("/leader/toRestartPage")
	@ResponseBody
	public ModelAndView projectRestorePage(HttpSession session, String projectId,String category) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("auction/center_auditor/project-pause-restore");
		mv.addObject("projectId", projectId);
		mv.addObject("category", category);
		return mv;
	}

	/**
		 * @Author：shy
		 * @Description: 提交重启申请
	     *@Date:下午 2:51   2017/12/4 0004
		 */
	@RequestMapping("/leader/restartApply")
	@ResponseBody
    public void restartApplyJ(HttpSession session, String projectId,String restoreReason,String category,HttpServletResponse resp){
		   User user = (User) session.getAttribute("loginUser");
		   AuctionInfo pro =this.auctionService.get(AuctionInfo.class,projectId);
		  if(category.equals("0")){
		   pro.setPauseFlagJ(PAUSE_RESTORE_J);
		   this.auctionService.saveOrUpdate(pro);
          //流程 任务完成
            Task task = workflowProcessInstanceService.findTask(pro.getWorkflowId());
            Map<String, Object> variables = new HashMap<String, Object>();
            variables.put("manager", "bizmanager");              //设置 审核人
            // 添加批注
		try {
			workflowProcessInstanceService.addComment(user.getLoginName(), task.getId(), pro.getWorkflowId(),"pauseDeal_J", restoreReason);
            workflowProcessInstanceService.complete(task.getId(), variables);
			resp.getWriter().print(Constant.SAVE_SUCCESS);

		}catch (Exception e){
			e.printStackTrace();
		}
      }else if (category.equals("1")){
          pro.setPauseFlagJ(PAUSE_RESTORE_Z);
		  this.auctionService.saveOrUpdate(pro);
		   //流程 任务完成
			Task task = workflowProcessInstanceService.findTask(pro.getWorkflowId());
			Map<String, Object> variables = new HashMap<String, Object>();
			variables.put("manager", "bizmanager");
          try {
			workflowProcessInstanceService.addComment(user.getLoginName(), task.getId(), pro.getWorkflowId(),"pauseDeal_Z", restoreReason);
            workflowProcessInstanceService.complete(task.getId(), variables);
			resp.getWriter().print(Constant.SAVE_SUCCESS);
		}catch (Exception e){
			e.printStackTrace();
		}
		}
	}

	/**
	 * @description 提交撤销申请页面
	 * @author shy
	 * @date 2016-9-2
	 */
	@RequestMapping("/leader/toRevokePageJ")
	@ResponseBody
	public ModelAndView projectRevokePage(HttpSession session, String projectId) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("auction/center_auditor/project-revoke");
		mv.addObject("projectId", projectId);
		return mv;
	}

	/**
		 * @Author：shy
		 * @Description: 提交撤销申请
	     *@Date:下午 2:51   2017/12/4 0004
		 */
	@RequestMapping("/leader/revokeApplyJ")
	@ResponseBody
    public void revokeApplyJ(HttpSession session, String projectId,String revokeReason,String pauseCategory,HttpServletResponse resp){
		   User user = (User) session.getAttribute("loginUser");
		   AuctionInfo pro =this.auctionService.get(AuctionInfo.class,projectId);
		   pro.setPauseFlagJ(PAUSE_REVOKE_J);
		   this.auctionService.saveOrUpdate(pro);
          //流程 任务完成
            Task task = workflowProcessInstanceService.findTask(pro.getWorkflowId());
            Map<String, Object> variables = new HashMap<String, Object>();
            variables.put("manager", "bizmanager");              //设置 审核人
            // 添加批注
		try {
			workflowProcessInstanceService.addComment(user.getLoginName(), task.getId(), pro.getWorkflowId(),"pauseDeal_J", revokeReason);
            workflowProcessInstanceService.complete(task.getId(), variables);
			resp.getWriter().print(Constant.SAVE_SUCCESS);

		}catch (Exception e){
			e.printStackTrace();
		}
	}


	/**
	 * @description 提交流标申请页面
	 * @author shy
	 * @date 2016-9-2
	 */
	@RequestMapping("/leader/toflowPage")
	@ResponseBody
	public ModelAndView toflowPage(HttpSession session, String projectId) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("auction/center_auditor/project-flow");
		mv.addObject("projectId", projectId);
		return mv;
	}

	/**
		 * @Author：shy
		 * @Description: 提交流标申请
	     *@Date:下午 2:51   2017/12/4 0004
		 */
	@RequestMapping("/leader/flowApply")
	@ResponseBody
    public void flowApply(HttpSession session, String projectId,String flowReason,HttpServletResponse resp){
		   User user = (User) session.getAttribute("loginUser");
		   AuctionInfo pro =this.auctionService.get(AuctionInfo.class,projectId);
		   pro.setPauseFlagJ(PAUSE_FLOW_Z);
		   this.auctionService.saveOrUpdate(pro);
          //流程 任务完成
            Task task = workflowProcessInstanceService.findTask(pro.getWorkflowId());
            Map<String, Object> variables = new HashMap<String, Object>();
            variables.put("manager", "bizmanager");              //设置 审核人
            // 添加批注
		try {
			workflowProcessInstanceService.addComment(user.getLoginName(), task.getId(), pro.getWorkflowId(),"pauseDeal_Z", flowReason);
            workflowProcessInstanceService.complete(task.getId(), variables);
			resp.getWriter().print(Constant.SAVE_SUCCESS);

		}catch (Exception e){
			e.printStackTrace();
		}
	}



	/**
		 * @Author：shy
		 * @Description:暂停结果审核
	     *@Date:下午 8:35   2017/12/4 0004
		 */
	    @RequestMapping("/leader/toPauseDealAuditPage")
	    @ResponseBody
	public ModelAndView toPauseDealAuditPage(HttpSession session, String projectId,String category) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/auction/bizmanager/pause-deal-audit");
		mv.addObject("projectId", projectId);
		mv.addObject("category", category);
		return mv;
	}



    /**
	 * @description 业务管理员审核暂停处理结果
	 * @author shy
	 * @throws IOException
	 * @date 2016-12-5
	 */
	@RequestMapping("/bizmanager/auditProjectPauseDeal")
	@ResponseBody
	public String auditProjectPauseDeal(ProjectPause projectPause, HttpSession session) throws IOException {
		User user = (User) session.getAttribute("loginUser");
		AuctionInfo pro = this.auctionService.get(AuctionInfo.class, projectPause.getProjectId());
		Task task = workflowProcessInstanceService.findTask(pro.getWorkflowId());
		Map<String, Object> variables = new HashMap<String, Object>();
		if (projectPause.getCategory().equals("0")) {//竞价公示
			if (projectPause.getResult().equals("1")) {//审核通过
				//流程 任务完成
				variables.put("auditor", pro.getAuditId());
				variables.put("question1", true);
				workflowProcessInstanceService.addComment(user.getLoginName(), task.getId(), pro.getWorkflowId(), "pauseDeal_J", projectPause.getReplay());
				workflowProcessInstanceService.complete(task.getId(), variables);
				return Constant.SAVE_SUCCESS;
			} else if (projectPause.getResult().equals("2")) {//审核不通过
				variables.put("question1", false);
				workflowProcessInstanceService.addComment(user.getLoginName(), task.getId(), pro.getWorkflowId(), "pauseDeal_J", projectPause.getReplay());
				workflowProcessInstanceService.complete(task.getId(), variables);
				return Constant.SAVE_SUCCESS;
			}

		}else if(projectPause.getCategory().equals("1")){//中标公示
           	if (projectPause.getResult().equals("1")) {//审核通过
				//流程 任务完成
				variables.put("auditor", pro.getAuditId());
				variables.put("question2", false);
				workflowProcessInstanceService.addComment(user.getLoginName(), task.getId(), pro.getWorkflowId(), "pauseDeal_Z", projectPause.getReplay());
				workflowProcessInstanceService.complete(task.getId(), variables);
				return Constant.SAVE_SUCCESS;
			} else if (projectPause.getResult().equals("2")) {//审核不通过
				variables.put("question2", true);
				workflowProcessInstanceService.addComment(user.getLoginName(), task.getId(), pro.getWorkflowId(), "pauseDeal_Z", projectPause.getReplay());
				workflowProcessInstanceService.complete(task.getId(), variables);
				return Constant.SAVE_SUCCESS;
			}
		}
		return Constant.SAVE_UN_SUCCESS;
	}

	 /**
		 * @Author：shy
		 * @Description:中心审核人项目撤销（已审核）
	     *@Date:上午 11:33   2017/12/5 0005
		 */
	   @RequestMapping("/leader/revoke")
	   @ResponseBody
	   public void revoke(HttpSession session, HttpServletResponse resp,String projectId){
             AuctionInfo pro = this.auctionService.get(AuctionInfo.class,projectId);
             Task task = workflowProcessInstanceService.findTask(pro.getWorkflowId());
             Map<String, Object> variables = new HashMap<String, Object>();
			 variables.put("continue1",false);
			 try {
			 	workflowProcessInstanceService.complete(task.getId(), variables);
			    resp.getWriter().print(Constant.SAVE_SUCCESS);
			 }catch (Exception e){
			 	e.printStackTrace();
			 }
	     }

	       /**
	     	 * @Author：shy
	     	 * @Description:进入中心审核人项目重启页面 (竞价公示)（已审核）
	         *@Date:下午 2:19   2017/12/5 0005
	     	 */
	      @RequestMapping("/leader/toRestoreJPage")
          public ModelAndView toRestoreJPage(HttpSession session, String projectId){
	      	  int auctionPublicity = dataSetService.getDataSet().getAuctionPublicity();//竞价公示期
	          AuctionInfo pro =this.auctionService.get(AuctionInfo.class,projectId);
	          ModelAndView mv = new ModelAndView();
	          DataSet dataset = dataSetService.get(DataSet.class, Constant.DATASET_ID);
	          mv.setViewName("auction/center_auditor/project-restoreJ");
	          mv.addObject("auctionPublicity",auctionPublicity);
		      mv.addObject("pro", pro);
		      mv.addObject("dataset",dataset);
              return mv;
           }

           /**
           	 * @Author：shy
           	 * @Description:中心审核人项目重启 设置开标时间 (竞价公示)（已审核）
             *@Date:下午 2:48   2017/12/5 0005
           	 */
           @RequestMapping("/leader/restoreJ")
           @ResponseBody
           public void restoreJ(HttpSession session, HttpServletResponse resp,String projectId,String bidStartDateStr, String bidStartTimeStr){
                 AuctionInfo pro = this.auctionService.get(AuctionInfo.class,projectId);
                 // 开标时间处理
                 Date bidStartTime = null;
			     Date bidEndTime = null;
				 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				 if (bidStartDateStr != null && !bidStartDateStr.isEmpty()) {
					 String bidStartStr = bidStartDateStr + " " + bidStartTimeStr + ":00:00";
					 bidStartTime = StringUtil.StringToDate(bidStartStr);
				 }
                 pro.setAuctionStart(bidStartTime);//更新开标时间
			     if (bidStartDateStr != null && !bidStartDateStr.isEmpty()) {
				     String bidStartStr = bidStartDateStr + " " + bidStartTimeStr + ":30:00";
				     bidEndTime = StringUtil.StringToDate(bidStartStr);
			     }
			     pro.setAuctionEnd(bidEndTime);

                 //流程
                 Task task = workflowProcessInstanceService.findTask(pro.getWorkflowId());
                 Map<String, Object> variables = new HashMap<String, Object>();
                 variables.put("continue1",true);

			     Long time = bidStartTime.getTime();
			     time = time - 1 * 60 * 1000;//提前1分钟开始竞价流程
			     Date auctionPublishEndTime = new Date(time);
			     variables.put("auctionPublishEndTime", StringUtil.getISODate(auctionPublishEndTime));


			     time = pro.getAuctionEnd().getTime();
			     time = time + 1 * 60 * 1000;//延迟1分钟结束竞价流程
			     Date auctionEndTime = new Date(time);//竞价结束时间
			     variables.put("auction_end_time", StringUtil.getISODate(auctionEndTime));//结束时间


                 try {
                    this.auctionService.saveOrUpdate(pro);
                    workflowProcessInstanceService.complete(task.getId(), variables);
                    resp.getWriter().print(Constant.SAVE_SUCCESS);
                 }catch (Exception e){
                    e.printStackTrace();
                 }
             }


	       /**
	     	 * @Author：shy
	     	 * @Description:进入中心审核人项目重启页面 （中标公示）（已审核）
	         *@Date:下午 2:19   2017/12/5 0005
	     	 */
	      @RequestMapping("/leader/toRestoreZPage")
          public ModelAndView toRestoreZPage(HttpSession session, String projectId){
	          AuctionInfo pro =this.auctionService.get(AuctionInfo.class,projectId);
	          ModelAndView mv = new ModelAndView();
	          mv.setViewName("auction/center_auditor/project-restoreZ");
		      mv.addObject("pro", pro);
              return mv;
           }


	       /**
           	 * @Author：shy
           	 * @Description:中心审核人项目重启 设置中标公示结束时间 （中标公示）（已审核）
             *@Date:下午 2:48   2017/12/5 0005
           	 */
           @RequestMapping("/leader/restoreZ")
           @ResponseBody
           public void restoreZ(HttpSession session, HttpServletResponse resp,String projectId,String hitShowEndString){
                 AuctionInfo pro = this.auctionService.get(AuctionInfo.class,projectId);
              //中标公示结束时间处理
                 Date hitShowEnd = null;
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    try {
                      hitShowEnd= sdf.parse(hitShowEndString);
					} catch (Exception e){
                    	e.printStackTrace();
					}
                 pro.setHitShowEnd(hitShowEnd);
                 //流程
                 Task task = workflowProcessInstanceService.findTask(pro.getWorkflowId());
                 Map<String, Object> variables = new HashMap<String, Object>();
                 variables.put("continue2",true);
                 variables.put("publishEndTime",StringUtil.getISODate(hitShowEnd));
                 try {
                    this.auctionService.saveOrUpdate(pro);
                    workflowProcessInstanceService.complete(task.getId(), variables);
                    resp.getWriter().print(Constant.SAVE_SUCCESS);
                 }catch (Exception e){
                    e.printStackTrace();
                 }
             }


        /**
		 * @Author：shy
		 * @Description:中心审核人项目流标（已审核）
	     *@Date:上午 11:33   2017/12/5 0005
		 */
	   @RequestMapping("/leader/flow")
	   @ResponseBody
	   public void flow(HttpSession session, HttpServletResponse resp,String projectId){
             AuctionInfo pro = this.auctionService.get(AuctionInfo.class,projectId);
             pro.setWinnerId("");//清空中标信息
             pro.setWinnerName("");//清空中标信息
		   //设置流标公示时间
             int flowPublicity = dataSetService.getDataSet().getFlowPublicity();//公示期
//             Date showStart = DateUtils.computeWorkDayDate(holidaySetService, new Date(), 0);//公示开始时间
		     pro.setFlowshowStart(new Date());//流标开始时间
             Date showEnd = DateUtils.computeWorkDayDate(holidaySetService, new Date(), flowPublicity);//公示结束时间
             //流标结束时间
		     pro.setFlowshowEnd(showEnd);
             this.auctionService.saveOrUpdate(pro);
             Task task = workflowProcessInstanceService.findTask(pro.getWorkflowId());
             Map<String, Object> variables = new HashMap<String, Object>();
			 variables.put("continue2",false);
			 variables.put("terminalEndTime",StringUtil.getISODate(showEnd));
			 try {
			 	workflowProcessInstanceService.complete(task.getId(), variables);
			    resp.getWriter().print(Constant.SAVE_SUCCESS);
			 }catch (Exception e){
			 	e.printStackTrace();
			 }
	     }


}
